package com.ysx.teacher.day20210906;

public class Ch05 {

    public static void main(String[] args) {

        // 输入一行字符，分别统计出其中英文字母、空格、数字、和其他字符的个数

        String str="abc   12345 @#$%^&*()";


        char[] array = str.toCharArray();
        int englishCounter=0;
        int numberCounter=0;
        int spaceCounter=0;

        for(int index=0;index<array.length;index++){
            char r=array[index];
            boolean y=false;

            // HashMap
            if(judge(r,checkCondition(r,"english"))){
                englishCounter++;
            }
            if(judge(r,checkCondition(r,"number"))){
                numberCounter++;
            }
            if(judge(r,checkCondition(r,"space"))){
                spaceCounter++;
            }


        }

        System.out.println("englishCounter="+englishCounter);
        System.out.println("numberCounter="+numberCounter);
        System.out.println("spaceCounter="+spaceCounter);

    }

    public static boolean checkCondition(char r,String condition){
        boolean jieguo =false;
        if(condition.equals("english")){
            jieguo=r>=97&&r<=122 || r>=65&&r<=90;
        }else if(condition.equals("number")){
            jieguo=r>=48 && r<=57;
        }else{
            jieguo=r==32;
        }
        return jieguo;
    }

    public static boolean judge(char r,boolean range){
        boolean rs =false;
        //boolean range=r>=97&&r<=122 || r>=65&&r<=90;
        if(range){
            rs=true;
        }
        return  rs;
    }





}
